package com.jilefojing.beans.pojos.enhanced;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

import com.jilefojing.beans.enums.ItemTypeEnumForSource;
import com.jilefojing.beans.pojos.Statistics;
import com.jilefojing.beans.pojos.enhanced.base.BaseEnhanced;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月19日 20时40分29秒
 */
public class EnhancedStatistics extends BaseEnhanced {
	public EnhancedStatistics(Statistics statistics) {
		// TODO 自动生成 细微误差自己调整
		if (statistics.getId() != null) {
			this.id = statistics.getId();
		}
		if (statistics.getItemType() != null) {
			this.itemType = ItemTypeEnumForSource
					.getItemTypeEnumByCode(statistics.getItemType());
		}
		if (statistics.getItemId() != null && this.itemType != null) {
			try {
				Class<? extends BaseEnhanced> _EnhancedClass = this.itemType
						.getEnhancedItemClass();
				BaseEnhanced _EnhancedItem = _EnhancedClass.newInstance();
				for (Method _Method : _EnhancedClass.getDeclaredMethods()) {
					if (_Method.getName().equals("setId")) {
						_Method.invoke(_EnhancedItem, statistics.getItemId());
						break;
					}
				}
				this.enhancedItem = _EnhancedItem;
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		if (statistics.getCountComment() != null) {
			this.countComment = statistics.getCountComment();
		}
		if (statistics.getCountWatch() != null) {
			this.countWatch = statistics.getCountWatch();
		}
		this.createTime = statistics.getCreateTime();
		this.updateTime = statistics.getUpdateTime();
		if (statistics.getCountPraise() != null) {
			this.countPraise = statistics.getCountPraise();
		}
		if (statistics.getCountFavorite() != null) {
			this.countFavorite = statistics.getCountFavorite();
		}

		if (statistics.getCountWrite() != null) {
			this.countWrite = statistics.getCountWrite();
		}
	}

	public EnhancedStatistics() {
	}

	private long id;
	private ItemTypeEnumForSource itemType;
	private BaseEnhanced enhancedItem;
	private long countComment;
	private long countWatch;
	private long countPraise;
	private long countFavorite;
	private long countWrite;

	private Date createTime;
	private Date updateTime;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public ItemTypeEnumForSource getItemType() {
		return itemType;
	}

	public void setItemType(ItemTypeEnumForSource itemType) {
		this.itemType = itemType;
	}

	public BaseEnhanced getEnhancedItem() {
		return enhancedItem;
	}

	public void setEnhancedItem(BaseEnhanced enhancedItem) {
		this.enhancedItem = enhancedItem;
	}

	public long getCountComment() {
		return countComment;
	}

	public void setCountComment(long countComment) {
		this.countComment = countComment;
	}

	public long getCountWatch() {
		return countWatch;
	}

	public void setCountWatch(long countWatch) {
		this.countWatch = countWatch;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public long getCountPraise() {
		return countPraise;
	}

	public void setCountPraise(long countPraise) {
		this.countPraise = countPraise;
	}

	public long getCountFavorite() {
		return countFavorite;
	}

	public void setCountFavorite(long countFavorite) {
		this.countFavorite = countFavorite;
	}

	public long getCountWrite() {
		return countWrite;
	}

	public void setCountWrite(long countWrite) {
		this.countWrite = countWrite;
	}

}